package il.ac.tau.arielgue.outxing.helpers;

import il.ac.tau.arielgue.outxing.agents.OutXingOrganism;
import il.ac.tau.arielgue.outxing.agents.UniformOrganism;
import proevolution.agents.Organism;
import proevolution.helpers.OrganismTransformation;

public class UniformTransformation implements OrganismTransformation {

	@Override
	public Organism transform(Organism original) {
		UniformOrganism transformed = null;

		if (original instanceof UniformOrganism) {
			transformed = (UniformOrganism) original;
		} else if (original instanceof OutXingOrganism) {
			OutXingOrganism castOriginal = (OutXingOrganism) original;
			transformed = (UniformOrganism) UniformOrganism.create(castOriginal);
			// sets the gender from the random created to the original's
			transformed.setMale(castOriginal.isMale()); 
			transformed.setOutXingModifier(OutXingOrganism.HOMOZYGOT_AA);
		} else {
			throw new ClassCastException("Can't cast organism of type "
					+ original.getClass().getName() + " to type "
					+ OutXingOrganism.class.getName());
		}

		return transformed;
	}

	@Override
	public String getTargetName() {
		return "Uniform Outcrosser";
	}
}
